//获取应用实例
var app = getApp()
var util = require('../../utils/util.js');
var commonService = require('../../services/commonService.js');
var userGroupService = require('../../services/userGroupService.js');
Page({
  data: {
    group_id: '',
    groupInfo: {},
  },
  onLoad: function (options) {
    var that = this;
    that.setData({
      group_id: options.group_id
    })
    that.getGroupDetail();
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  getGroupDetail: function () {
    var that = this;
    userGroupService.groupDetail({
      group_id: that.data.group_id,
      user_id: app.globalData.sysUserInfo.userId,
      success: function (res) {
        var groupInfo = res;
        that.setData({
          groupInfo: groupInfo
        })
      }
    })
  },
  manageMember: function (e) {
    var gid = e.currentTarget.dataset.gid;
    wx.navigateTo({
      url: '../memberList/memberList?group_id=' + gid,
    })
  },
  setMainGroup: function (e) {
    var that = this;
    var gid = e.currentTarget.dataset.gid;
    userGroupService.setMainGroup({
      group_id: gid,
      user_id: app.globalData.sysUserInfo.userId,
      success: function (res) {
        that.data.groupInfo.is_primary_group = 1;
        that.setData({
          groupInfo: that.data.groupInfo
        })
        wx.showToast({
          title: '设置成功',
        })
      }
    })
  },
  backTopPrevNavigate: function () {
    wx.navigateBack()
  }
})